#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *hello(void *arg){
    printf("hello world\n");
    #if 0
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); //使用异步取消线程
    #endif
    int i = 0;
    while (1)
    {
        #if 1

        pthread_testcancel();//使用定点取消线程
        #endif
        printf("hello world %d\n", i++);
    }
    
}
int main(int argc, char const *argv[])
{
    pthread_t pid;
    pthread_create(&pid, NULL, hello, NULL);
    printf("main thread\n");
    sleep(1);
    pthread_cancel(pid);
    printf("main thread end\n");
    return 0;
}
